<?php include("../config.php"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title><?php echo $sitename; ?> - Sysop: Database Backup</title>
<meta name="description" content="<?php echo $sitename; ?> - Sysop: Database Backup">
<meta name="keywords" content="free to try, software, shareware, freeware, developers, vendors, download, PAD">
<meta name="author" content="Andrey Aleksanyants, M.D.">
<meta name="copyright" content="easy HTools">
<meta http-equiv="imagetoolbar" content="no">
<link rel="stylesheet" type="text/css" href="../<?php echo $cssfile; ?>">
<link rel="shortcut icon" href="../favicon.ico">
</head>
<body>
<table class="tmain" align="center" width="90%" cellspacing="0" cellpadding="0">
<tr>
<td class="tmain">
<table class="tlogo" align="center" width="100%" cellspacing="0" cellpadding="4">
<tr>
<td align="right">
<p><a href="index.php">Home</a></p>
</td>
</tr>
</table>
</td>
</tr><tr>
<td class="tmain">
<br>
<table align="center" width="100%" border="0" cellspacing="0" cellpadding="1">
<tr valign="top">
<td class="tbody">
<h1><?php echo $sitename; ?> - Sysop: Database Backup</h1>
<?php

if(!($link_id = mysql_connect($dbhost, $userid, $userpassword))) {
	die("<p><b>Error connecting to the database server:</b> " . mysql_error() . "</p>\n");
}
mysql_select_db($dbname);

$cr = chr(13);
$lf = chr(10);
$bkfile = "backup.bin";
$fp = fopen($bkfile,"w");
fwrite($fp,"USE asp;\r\n\r\n");
$result = mysql_query("SELECT * FROM paddata ORDER BY company, title", $link_id);
$numrows = 0;
if($result) $numrows = mysql_num_rows($result);
echo "<p>There are <b>" . $numrows . "</b> PADs listed in table \"Paddata\". Saving table...</p><br>\n";
$n = mysql_num_fields($result);
while($query = mysql_fetch_row($result)) {
	$s = "INSERT INTO paddata VALUES(";
	for($i=0; $i<$n; $i++) {
		if($i>0) $s .= ", ";
		$t = addslashes($query[$i]);
		$t = str_replace($cr,"//r",$t);
		$t = str_replace($lf,"//n",$t);
		$s .= "'" . $t . "'";
	}
	$s .= ");\r\n";
	fwrite($fp,$s);
}
fwrite($fp,"\r\n");
fclose($fp);
chmod("backup.bin",0777);

echo "<p>Download <a href=\"" . $bkfile . "\">" . $bkfile . "</a> file (" . filesize($bkfile) . " Bytes) to your local drive.</p><br>\n";

mysql_close($link_id);
?>
<br>

</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>